home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / inst.pas < prev    next >
Pascal/Delphi Source File  |  1992-11-16  |  1KB  |  55 lines

  1. program Instances;
  2. { uploaded by Ron Aaron as a demonstration of how to
  3.   prevent multiple instances of a program in different
  4.   VMs.  This program will work compiled for Windows, DOS
  5.   or DPMI.
  6. }
  7. uses  strings,
  8. {$IFDEF WINDOWS}
  9.         wincrt
  10. {$ELSE}
  11.        crt
  12. {$ENDIF}
  13. ;
  14.  
  15. var
  16.    { Inter Program Area: 16 bytes set aside by IBM for
  17.      just this sort of thing...
  18.    }
  19.    IPA : array[0..15] of char absolute $40:$f0;
  20.  
  21. const
  22.    ident : PChar = 'INSTTEST';
  23.  
  24. function isrunning : boolean;
  25. begin
  26.      if StrComp(IPA, ident) = 0 then
  27.         isrunning := true
  28.      else
  29.         isrunning := false;
  30. end;
  31.  
  32. procedure install;
  33. begin
  34.      StrCopy(IPA, ident);
  35. end;
  36.  
  37. procedure deinstall;
  38. begin
  39.      StrCopy(IPA,'xxxxx');
  40. end;
  41.  
  42. begin
  43.      if isrunning then
  44.      begin
  45.           writeln('Previous copy is running.');
  46.      end
  47.      else
  48.      begin
  49.           install;
  50.           writeln('No previous copy is running.  Press any key to quit...');
  51.           while not keypressed do
  52.                 ;
  53.           deinstall;
  54.      end;
  55. end.